package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.Role;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.SimpleRole;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWListSubItem;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

/**
 * 
 * 推荐集合
 * 
 * @author mujianchen
 * 
 */
public class UITuiJian implements IUIWindows
{
	public static final byte TUIJIAN_HAOYOU = 0;//推荐好友
	public static final byte TUIJIAN_SHIFU = 1;//推荐师傅
	public static final byte TUIJIAN_TUDI = 2;//推荐徒弟

	public Bitmap m_tjBitmap_guanbi = null;//关闭按钮
	public Bitmap m_tjBitmap01 = null;//按钮
	public Bitmap m_tjBitmap01_ax = null;//按钮

	//标题
	public Bitmap m_tjBitmap_HY = null;//推荐好友
	public Bitmap m_tjBitmap_TD = null;//推荐弟子
	public Bitmap m_tjBitmap_SF = null;//推荐师傅

	//推荐好友
	public DWFrame m_haoyou_Frame = null;
	public DWTitle m_haoyou_Title = null;
	public DWImageBox m_haoyou_ttImageBox = null;
	public DWBackground m_haoyou_Background = null;
	public DWBackground m_haoyou_Background01 = null;
	public DWImageBox m_haoyou_Guanbi = null;
	public DWListbox m_haoyou_list = null;
	public CopyOnWriteArrayList<SimpleRole> m_data_list = new CopyOnWriteArrayList<SimpleRole>();

	public DWTextbox[] m_haoyou_Textboxs = new DWTextbox[7];

	public DWTextbox m_haoyou_Textbox = null;//下方提示

	public int m_haoyou_size = 0;//推荐好友列表长度

	public int m_haoyou_index = 0;

	public DWListSubItem[] m_haoyou_lsItem;
	public DWTextbox[] m_haoyou_lsTextbox01;
	public DWTextbox[] m_haoyou_lsTextbox02;
	public DWTextbox[] m_haoyou_lsTextbox03;
	public DWTextbox[] m_haoyou_lsTextbox04;
	public DWTextbox[] m_haoyou_lsTextbox05;
	public DWTextbox[] m_haoyou_lsTextbox06;
	public DWTextbox[] m_haoyou_lsTextbox07;
	public DWButton[] m_haoyou_lsButton;

	//推荐徒弟
	public DWFrame m_tudi_Frame = null;
	public DWTitle m_tudi_Title = null;
	public DWImageBox m_tudi_ttImageBox = null;
	public DWBackground m_tudi_Background = null;
	public DWBackground m_tudi_Background01 = null;
	public DWImageBox m_tudi_Guanbi = null;
	public DWListbox m_tudi_list = null;

	public DWTextbox[] m_tudi_Textboxs = new DWTextbox[7];

	public DWTextbox m_tudi_Textbox = null;//下方提示

	public int m_tudi_size = 0;//推荐徒弟列表长度

	public int m_tudi_index = 0;

	public DWListSubItem[] m_tudi_lsItem;
	public DWTextbox[] m_tudi_lsTextbox01;
	public DWTextbox[] m_tudi_lsTextbox02;
	public DWTextbox[] m_tudi_lsTextbox03;
	public DWTextbox[] m_tudi_lsTextbox04;
	public DWTextbox[] m_tudi_lsTextbox05;
	public DWTextbox[] m_tudi_lsTextbox06;
	public DWTextbox[] m_tudi_lsTextbox07;
	public DWButton[] m_tudi_lsButton;

	//推荐师傅
	public DWFrame m_shifu_Frame = null;
	public DWTitle m_shifu_Title = null;
	public DWImageBox m_shifu_ttImageBox = null;
	public DWBackground m_shifu_Background = null;
	public DWBackground m_shifu_Background01 = null;
	public DWImageBox m_shifu_Guanbi = null;
	public DWListbox m_shifu_list = null;

	public DWTextbox[] m_shifu_Textboxs = new DWTextbox[7];

	public DWTextbox m_shifu_Textbox = null;//下方提示

	public int m_shifu_size = 0;//推荐师傅列表长度

	public int m_shifu_index = 0;

	public DWListSubItem[] m_shifu_lsItem;
	public DWTextbox[] m_shifu_lsTextbox01;
	public DWTextbox[] m_shifu_lsTextbox02;
	public DWTextbox[] m_shifu_lsTextbox03;
	public DWTextbox[] m_shifu_lsTextbox04;
	public DWTextbox[] m_shifu_lsTextbox05;
	public DWTextbox[] m_shifu_lsTextbox06;
	public DWTextbox[] m_shifu_lsTextbox07;
	public DWButton[] m_shifu_lsButton;

	/** 推荐好友界面 */
	public void tuijian_haoyou()
	{
		if (m_haoyou_Frame != null) {
			DWControlsManager.getInstance().removeControl(m_haoyou_Frame);
		}
		m_haoyou_Frame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 150);
		m_haoyou_Title = new DWTitle(null, m_haoyou_Frame);

		m_haoyou_ttImageBox = new DWImageBox(m_tjBitmap_HY);
		m_haoyou_ttImageBox.setNearAnchor(m_haoyou_Title, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM);

		m_haoyou_Guanbi = new DWImageBox(m_tjBitmap_guanbi);
		m_haoyou_Guanbi.setNearAnchor(m_haoyou_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_haoyou_Guanbi.setTouchZoomIn(20, 20);
		m_haoyou_Guanbi.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close(TUIJIAN_HAOYOU);
			}
		});

		m_haoyou_Background = new DWBackground(m_haoyou_Frame.getShowWidth() - 20,
				m_haoyou_Frame.getShowHeight() - 30);
		m_haoyou_Background.setNearAnchor(m_haoyou_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
		m_haoyou_Background.setFill(false);

		m_haoyou_Background01 = new DWBackground(m_haoyou_Frame.getShowWidth() - 20,
				m_haoyou_Title.getShowHeight() + 10);
		m_haoyou_Background01.setFill(true);
		m_haoyou_Background01.setNearAnchor(m_haoyou_Frame, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 20);

		m_haoyou_Textboxs[0] = new DWTextbox(null, m_haoyou_Background01.getShowWidth() / 4, 0);
		m_haoyou_Textboxs[1] = new DWTextbox(null, m_haoyou_Background01.getShowWidth() / 4, 0);
		m_haoyou_Textboxs[2] = new DWTextbox(null, m_haoyou_Background01.getShowWidth() / 4, 0);
		m_haoyou_Textboxs[3] = new DWTextbox(null, m_haoyou_Background01.getShowWidth() / 4, 0);
		m_haoyou_Textboxs[4] = new DWTextbox("<mark c=F5BA16>昵称</mark>");
		m_haoyou_Textboxs[5] = new DWTextbox("<mark c=F5BA16>等级</mark>");
		m_haoyou_Textboxs[6] = new DWTextbox("<mark c=F5BA16>职业</mark>");

		m_haoyou_Textboxs[0].setNearAnchor(m_haoyou_Background01, Tools.LEFT_VCENTER, Tools.LEFT_VCENTER);
		m_haoyou_Textboxs[1].setNearAnchor(m_haoyou_Textboxs[0], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_haoyou_Textboxs[2].setNearAnchor(m_haoyou_Textboxs[1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_haoyou_Textboxs[3].setNearAnchor(m_haoyou_Textboxs[2], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_haoyou_Textboxs[4].setNearAnchor(m_haoyou_Textboxs[0], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_haoyou_Textboxs[5].setNearAnchor(m_haoyou_Textboxs[1], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_haoyou_Textboxs[6].setNearAnchor(m_haoyou_Textboxs[2], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_haoyou_list = new DWListbox(m_haoyou_Frame.getShowWidth() - 20, m_haoyou_Frame.getShowHeight() - 170);
		m_haoyou_list.setNearAnchor(m_haoyou_Background01, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 5);
		m_haoyou_list.setLineSpacing(10);// 设置间距
		m_haoyou_list.setShowBackgroundRect(false);

		m_haoyou_Textbox = new DWTextbox("系统为您推荐以上好友，方便您摇钱树浇水等社交活动。", m_haoyou_Background.getShowWidth(), 80);
		m_haoyou_Textbox.setNearAnchor(m_haoyou_list, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM);

		m_haoyou_Frame.addControl(m_haoyou_Background);
		m_haoyou_Frame.addControl(m_haoyou_Background01);
		m_haoyou_Frame.addControl(m_haoyou_Title);
		m_haoyou_Frame.addControl(m_haoyou_Guanbi);
		m_haoyou_Frame.addControl(m_haoyou_list);
		for (int i = 0; i < m_haoyou_Textboxs.length; i++) {
			m_haoyou_Frame.addControl(m_haoyou_Textboxs[i]);
		}
		m_haoyou_Frame.addControl(m_haoyou_Textbox);
		m_haoyou_Frame.addControl(m_haoyou_ttImageBox);
		DWControlsManager.getInstance().addControl(m_haoyou_Frame);
	}

	/** 好友列表 */
	public void list_haoyou()
	{
		if (m_haoyou_list != null) {
			DWControlsManager.getInstance().removeControl(m_haoyou_list);
		}
		m_haoyou_size = m_data_list.size();
		m_haoyou_lsItem = new DWListSubItem[m_haoyou_size];
		m_haoyou_lsTextbox01 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsTextbox02 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsTextbox03 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsTextbox04 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsTextbox05 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsTextbox06 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsTextbox07 = new DWTextbox[m_haoyou_size];
		m_haoyou_lsButton = new DWButton[m_haoyou_size];

//		SimpleRole role = null;
		for (int i = 0; i < m_haoyou_size; i++) {
			final SimpleRole role = m_data_list.get(i);
			m_haoyou_lsItem[i] = new DWListSubItem();
			m_haoyou_lsItem[i].setAutoWideHigh(false);
			m_haoyou_lsItem[i].setShowWideHighUn(m_haoyou_Background.getShowWidth(), 34);

			m_haoyou_lsTextbox01[i] = new DWTextbox(null, m_haoyou_lsItem[i].getShowWidth() / 4, 0);
			m_haoyou_lsTextbox02[i] = new DWTextbox(null, m_haoyou_lsItem[i].getShowWidth() / 4, 0);
			m_haoyou_lsTextbox03[i] = new DWTextbox(null, m_haoyou_lsItem[i].getShowWidth() / 4, 0);
			m_haoyou_lsTextbox04[i] = new DWTextbox(null, m_haoyou_lsItem[i].getShowWidth() / 4, 0);
			m_haoyou_lsTextbox05[i] = new DWTextbox(role.m_name);
			m_haoyou_lsTextbox06[i] = new DWTextbox(String.valueOf(role.m_grade));
			m_haoyou_lsTextbox07[i] = new DWTextbox(Role.ROLE_VOCATION_LIST[role.m_vocation]);

			m_haoyou_lsTextbox01[i].setNearAnchor(m_haoyou_lsItem[i], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER);
			m_haoyou_lsTextbox02[i].setNearAnchor(m_haoyou_lsTextbox01[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_haoyou_lsTextbox03[i].setNearAnchor(m_haoyou_lsTextbox02[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_haoyou_lsTextbox04[i].setNearAnchor(m_haoyou_lsTextbox03[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_haoyou_lsTextbox05[i]
					.setNearAnchor(m_haoyou_lsTextbox01[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_haoyou_lsTextbox06[i]
					.setNearAnchor(m_haoyou_lsTextbox02[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_haoyou_lsTextbox07[i]
					.setNearAnchor(m_haoyou_lsTextbox03[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

			m_haoyou_lsButton[i] = new DWButton("添加", m_tjBitmap01);
			m_haoyou_lsButton[i].setTextColor(0xFFEFFF40);
			m_haoyou_lsButton[i].setDownImage(m_tjBitmap01_ax);
			m_haoyou_lsButton[i].setNearAnchor(m_haoyou_lsTextbox04[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_haoyou_lsButton[i].addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
//					int index = m_haoyou_list.getTouchIndex();
					DWGameManager.getInstance().getSendMessage().sendSocialAdd(UISocial.SOCIAL_TYPE_FRIEND,
							role.m_gameID, role.m_name);
				}
			});

			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox01[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox02[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox03[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox04[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox05[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox06[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsTextbox07[i]);
			m_haoyou_lsItem[i].addControls(m_haoyou_lsButton[i]);
			m_haoyou_list.addSubItem(m_haoyou_lsItem[i]);
		}
	}

	/** 推荐徒弟界面 */
	public void tuijian_tudi()
	{
		if (m_tudi_Frame != null) {
			DWControlsManager.getInstance().removeControl(m_tudi_Frame);
		}
		m_tudi_Frame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 150);
		m_tudi_Title = new DWTitle(null, m_tudi_Frame);

		m_tudi_ttImageBox = new DWImageBox(m_tjBitmap_TD);
		m_tudi_ttImageBox.setNearAnchor(m_tudi_Title, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM);

		m_tudi_Guanbi = new DWImageBox(m_tjBitmap_guanbi);
		m_tudi_Guanbi.setNearAnchor(m_tudi_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_tudi_Guanbi.setTouchZoomIn(20, 20);
		m_tudi_Guanbi.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close(TUIJIAN_TUDI);
			}
		});

		m_tudi_Background = new DWBackground(m_tudi_Frame.getShowWidth() - 20,
				m_tudi_Frame.getShowHeight() - 30);
		m_tudi_Background.setNearAnchor(m_tudi_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
		m_tudi_Background.setFill(false);

		m_tudi_Background01 = new DWBackground(m_tudi_Frame.getShowWidth() - 20,
				m_tudi_Title.getShowHeight() + 10);
		m_tudi_Background01.setFill(true);
		m_tudi_Background01.setNearAnchor(m_tudi_Frame, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 20);

		m_tudi_Textboxs[0] = new DWTextbox(null, m_tudi_Background01.getShowWidth() / 4, 0);
		m_tudi_Textboxs[1] = new DWTextbox(null, m_tudi_Background01.getShowWidth() / 4, 0);
		m_tudi_Textboxs[2] = new DWTextbox(null, m_tudi_Background01.getShowWidth() / 4, 0);
		m_tudi_Textboxs[3] = new DWTextbox(null, m_tudi_Background01.getShowWidth() / 4, 0);
		m_tudi_Textboxs[4] = new DWTextbox("<mark c=F5BA16>昵称</mark>");
		m_tudi_Textboxs[5] = new DWTextbox("<mark c=F5BA16>等级</mark>");
		m_tudi_Textboxs[6] = new DWTextbox("<mark c=F5BA16>职业</mark>");

		m_tudi_Textboxs[0].setNearAnchor(m_tudi_Background01, Tools.LEFT_VCENTER, Tools.LEFT_VCENTER);
		m_tudi_Textboxs[1].setNearAnchor(m_tudi_Textboxs[0], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_tudi_Textboxs[2].setNearAnchor(m_tudi_Textboxs[1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_tudi_Textboxs[3].setNearAnchor(m_tudi_Textboxs[2], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_tudi_Textboxs[4].setNearAnchor(m_tudi_Textboxs[0], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_tudi_Textboxs[5].setNearAnchor(m_tudi_Textboxs[1], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_tudi_Textboxs[6].setNearAnchor(m_tudi_Textboxs[2], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_tudi_list = new DWListbox(m_tudi_Frame.getShowWidth() - 20, m_tudi_Frame.getShowHeight() - 170);
		m_tudi_list.setNearAnchor(m_tudi_Background01, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 5);
		m_tudi_list.setLineSpacing(10);// 设置间距
		m_tudi_list.setShowBackgroundRect(false);

		m_tudi_Textbox = new DWTextbox("系统为您推荐以上徒弟，方便您传道授业等社交活动。", m_tudi_Background.getShowWidth(), 80);
		m_tudi_Textbox.setNearAnchor(m_tudi_list, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM);

		m_tudi_Frame.addControl(m_tudi_Background);
		m_tudi_Frame.addControl(m_tudi_Background01);
		m_tudi_Frame.addControl(m_tudi_Title);
		m_tudi_Frame.addControl(m_tudi_Guanbi);
		m_tudi_Frame.addControl(m_tudi_list);
		for (int i = 0; i < m_tudi_Textboxs.length; i++) {
			m_tudi_Frame.addControl(m_tudi_Textboxs[i]);
		}
		m_tudi_Frame.addControl(m_tudi_Textbox);
		m_tudi_Frame.addControl(m_tudi_ttImageBox);
		DWControlsManager.getInstance().addControl(m_tudi_Frame);
	}

	/** 徒弟列表 */
	public void list_tudi()
	{
		if (m_tudi_list != null) {
			DWControlsManager.getInstance().removeControl(m_tudi_list);
		}
		m_tudi_size = m_data_list.size();
		m_tudi_lsItem = new DWListSubItem[m_tudi_size];
		m_tudi_lsTextbox01 = new DWTextbox[m_tudi_size];
		m_tudi_lsTextbox02 = new DWTextbox[m_tudi_size];
		m_tudi_lsTextbox03 = new DWTextbox[m_tudi_size];
		m_tudi_lsTextbox04 = new DWTextbox[m_tudi_size];
		m_tudi_lsTextbox05 = new DWTextbox[m_tudi_size];
		m_tudi_lsTextbox06 = new DWTextbox[m_tudi_size];
		m_tudi_lsTextbox07 = new DWTextbox[m_tudi_size];
		m_tudi_lsButton = new DWButton[m_tudi_size];

		for (int i = 0; i < m_tudi_size; i++) {
			final SimpleRole role = m_data_list.get(i);
			m_tudi_lsItem[i] = new DWListSubItem();
			m_tudi_lsItem[i].setAutoWideHigh(false);
			m_tudi_lsItem[i].setShowWideHighUn(m_tudi_Background.getShowWidth(), 34);

			m_tudi_lsTextbox01[i] = new DWTextbox(null, m_tudi_lsItem[i].getShowWidth() / 4, 0);
			m_tudi_lsTextbox02[i] = new DWTextbox(null, m_tudi_lsItem[i].getShowWidth() / 4, 0);
			m_tudi_lsTextbox03[i] = new DWTextbox(null, m_tudi_lsItem[i].getShowWidth() / 4, 0);
			m_tudi_lsTextbox04[i] = new DWTextbox(null, m_tudi_lsItem[i].getShowWidth() / 4, 0);
			m_tudi_lsTextbox05[i] = new DWTextbox(role.m_name);
			m_tudi_lsTextbox06[i] = new DWTextbox(String.valueOf(role.m_grade));
			m_tudi_lsTextbox07[i] = new DWTextbox(Role.ROLE_VOCATION_LIST[role.m_vocation]);

			m_tudi_lsTextbox01[i].setNearAnchor(m_tudi_lsItem[i], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER);
			m_tudi_lsTextbox02[i].setNearAnchor(m_tudi_lsTextbox01[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_tudi_lsTextbox03[i].setNearAnchor(m_tudi_lsTextbox02[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_tudi_lsTextbox04[i].setNearAnchor(m_tudi_lsTextbox03[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_tudi_lsTextbox05[i]
					.setNearAnchor(m_tudi_lsTextbox01[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_tudi_lsTextbox06[i]
					.setNearAnchor(m_tudi_lsTextbox02[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_tudi_lsTextbox07[i]
					.setNearAnchor(m_tudi_lsTextbox03[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

			m_tudi_lsButton[i] = new DWButton("添加", m_tjBitmap01);
			m_tudi_lsButton[i].setTextColor(0xFFEFFF40);
			m_tudi_lsButton[i].setDownImage(m_tjBitmap01_ax);
			m_tudi_lsButton[i].setNearAnchor(m_tudi_lsTextbox04[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_tudi_lsButton[i].addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
//					int index = m_tudi_list.getTouchIndex();
					DWGameManager.getInstance().getSendMessage().sendBaiShi(role.m_gameID);
				}
			});

			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox01[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox02[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox03[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox04[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox05[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox06[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsTextbox07[i]);
			m_tudi_lsItem[i].addControls(m_tudi_lsButton[i]);
			m_tudi_list.addSubItem(m_tudi_lsItem[i]);
		}
	}

	/** 推荐师傅界面 */
	public void tuijain_shifu()
	{
		if (m_shifu_Frame != null) {
			DWControlsManager.getInstance().removeControl(m_shifu_Frame);
		}
		m_shifu_Frame = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 150);
		m_shifu_Title = new DWTitle(null, m_shifu_Frame);

		m_shifu_ttImageBox = new DWImageBox(m_tjBitmap_SF);
		m_shifu_ttImageBox.setNearAnchor(m_shifu_Title, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM);

		m_shifu_Guanbi = new DWImageBox(m_tjBitmap_guanbi);
		m_shifu_Guanbi.setNearAnchor(m_shifu_Title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_shifu_Guanbi.setTouchZoomIn(20, 20);
		m_shifu_Guanbi.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				close(TUIJIAN_SHIFU);
			}
		});

		m_shifu_Background = new DWBackground(m_shifu_Frame.getShowWidth() - 20,
				m_shifu_Frame.getShowHeight() - 30);
		m_shifu_Background.setNearAnchor(m_shifu_Frame, Tools.HCENTER_BOTTOM, Tools.HCENTER_BOTTOM, 0, -10);
		m_shifu_Background.setFill(false);

		m_shifu_Background01 = new DWBackground(m_shifu_Frame.getShowWidth() - 20,
				m_shifu_Title.getShowHeight() + 10);
		m_shifu_Background01.setFill(true);
		m_shifu_Background01.setNearAnchor(m_shifu_Frame, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 20);

		m_shifu_Textboxs[0] = new DWTextbox(null, m_shifu_Background01.getShowWidth() / 4, 0);
		m_shifu_Textboxs[1] = new DWTextbox(null, m_shifu_Background01.getShowWidth() / 4, 0);
		m_shifu_Textboxs[2] = new DWTextbox(null, m_shifu_Background01.getShowWidth() / 4, 0);
		m_shifu_Textboxs[3] = new DWTextbox(null, m_shifu_Background01.getShowWidth() / 4, 0);
		m_shifu_Textboxs[4] = new DWTextbox("<mark c=F5BA16>昵称</mark>");
		m_shifu_Textboxs[5] = new DWTextbox("<mark c=F5BA16>等级</mark>");
		m_shifu_Textboxs[6] = new DWTextbox("<mark c=F5BA16>职业</mark>");

		m_shifu_Textboxs[0].setNearAnchor(m_shifu_Background01, Tools.LEFT_VCENTER, Tools.LEFT_VCENTER);
		m_shifu_Textboxs[1].setNearAnchor(m_shifu_Textboxs[0], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_shifu_Textboxs[2].setNearAnchor(m_shifu_Textboxs[1], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_shifu_Textboxs[3].setNearAnchor(m_shifu_Textboxs[2], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
		m_shifu_Textboxs[4].setNearAnchor(m_shifu_Textboxs[0], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_shifu_Textboxs[5].setNearAnchor(m_shifu_Textboxs[1], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_shifu_Textboxs[6].setNearAnchor(m_shifu_Textboxs[2], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_shifu_list = new DWListbox(m_shifu_Frame.getShowWidth() - 20, m_shifu_Frame.getShowHeight() - 170);
		m_shifu_list.setNearAnchor(m_shifu_Background01, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0, 5);
		m_shifu_list.setLineSpacing(10);// 设置间距
		m_shifu_list.setShowBackgroundRect(false);

		m_shifu_Textbox = new DWTextbox("系统为您推荐以上师傅，方便您拜师学习等社交活动。", m_shifu_Background.getShowWidth(), 80);
		m_shifu_Textbox.setNearAnchor(m_shifu_list, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM);

		m_shifu_Frame.addControl(m_shifu_Background);
		m_shifu_Frame.addControl(m_shifu_Background01);
		m_shifu_Frame.addControl(m_shifu_Title);
		m_shifu_Frame.addControl(m_shifu_Guanbi);
		m_shifu_Frame.addControl(m_shifu_list);
		for (int i = 0; i < m_shifu_Textboxs.length; i++) {
			m_shifu_Frame.addControl(m_shifu_Textboxs[i]);
		}
		m_shifu_Frame.addControl(m_shifu_Textbox);
		m_shifu_Frame.addControl(m_shifu_ttImageBox);
		DWControlsManager.getInstance().addControl(m_shifu_Frame);
	}

	/** 师傅列表 */
	public void list_shifu()
	{
		if (m_shifu_list != null) {
			DWControlsManager.getInstance().removeControl(m_shifu_list);
		}
		m_shifu_size = m_data_list.size();
		m_shifu_lsItem = new DWListSubItem[m_shifu_size];
		m_shifu_lsTextbox01 = new DWTextbox[m_shifu_size];
		m_shifu_lsTextbox02 = new DWTextbox[m_shifu_size];
		m_shifu_lsTextbox03 = new DWTextbox[m_shifu_size];
		m_shifu_lsTextbox04 = new DWTextbox[m_shifu_size];
		m_shifu_lsTextbox05 = new DWTextbox[m_shifu_size];
		m_shifu_lsTextbox06 = new DWTextbox[m_shifu_size];
		m_shifu_lsTextbox07 = new DWTextbox[m_shifu_size];
		m_shifu_lsButton = new DWButton[m_shifu_size];

		for (int i = 0; i < m_shifu_size; i++) {
			final SimpleRole role = m_data_list.get(i);
			m_shifu_lsItem[i] = new DWListSubItem();
			m_shifu_lsItem[i].setAutoWideHigh(false);
			m_shifu_lsItem[i].setShowWideHighUn(m_shifu_Background.getShowWidth(), 34);

			m_shifu_lsTextbox01[i] = new DWTextbox(null, m_shifu_lsItem[i].getShowWidth() / 4, 0);
			m_shifu_lsTextbox02[i] = new DWTextbox(null, m_shifu_lsItem[i].getShowWidth() / 4, 0);
			m_shifu_lsTextbox03[i] = new DWTextbox(null, m_shifu_lsItem[i].getShowWidth() / 4, 0);
			m_shifu_lsTextbox04[i] = new DWTextbox(null, m_shifu_lsItem[i].getShowWidth() / 4, 0);
			m_shifu_lsTextbox05[i] = new DWTextbox(role.m_name);
			m_shifu_lsTextbox06[i] = new DWTextbox(String.valueOf(role.m_grade));
			m_shifu_lsTextbox07[i] = new DWTextbox(Role.ROLE_VOCATION_LIST[role.m_vocation]);

			m_shifu_lsTextbox01[i].setNearAnchor(m_shifu_lsItem[i], Tools.LEFT_VCENTER, Tools.LEFT_VCENTER);
			m_shifu_lsTextbox02[i].setNearAnchor(m_shifu_lsTextbox01[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_shifu_lsTextbox03[i].setNearAnchor(m_shifu_lsTextbox02[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_shifu_lsTextbox04[i].setNearAnchor(m_shifu_lsTextbox03[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER);
			m_shifu_lsTextbox05[i]
					.setNearAnchor(m_shifu_lsTextbox01[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_shifu_lsTextbox06[i]
					.setNearAnchor(m_shifu_lsTextbox02[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_shifu_lsTextbox07[i]
					.setNearAnchor(m_shifu_lsTextbox03[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

			m_shifu_lsButton[i] = new DWButton("添加", m_tjBitmap01);
			m_shifu_lsButton[i].setTextColor(0xFFEFFF40);
			m_shifu_lsButton[i].setDownImage(m_tjBitmap01_ax);
			m_shifu_lsButton[i].setNearAnchor(m_shifu_lsTextbox04[i], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_shifu_lsButton[i].addListener(new DWListener() {

				public void OnDoubleClick()
				{

				}

				public void OnClick()
				{
//					int index = m_shifu_list.getTouchIndex();
					DWGameManager.getInstance().getSendMessage().sendBaiShi(role.m_gameID);
				}
			});

			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox01[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox02[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox03[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox04[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox05[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox06[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsTextbox07[i]);
			m_shifu_lsItem[i].addControls(m_shifu_lsButton[i]);
			m_shifu_list.addSubItem(m_shifu_lsItem[i]);
		}
	}

	public void init()
	{
		m_tjBitmap_guanbi = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");//关闭图片
		m_tjBitmap01 = UIWindows.createImage("/img/newui/anniu_1.gnp");//添加按钮
		m_tjBitmap01_ax = UIWindows.createImage("/img/newui/anniu_1ax.gnp");//添加按钮按下

		m_tjBitmap_HY = UIWindows.createImage("/img/newui/tuijianhaoyou_1.gnp");//推荐好友标题
		m_tjBitmap_TD = UIWindows.createImage("/img/newui/tuijiandizi_1.gnp");//推荐徒弟标题
		m_tjBitmap_SF = UIWindows.createImage("/img/newui/tuijianshifu_1.gnp");//推荐师傅标题
	}

	public void open(byte index)
	{
		switch (index) {
			case TUIJIAN_HAOYOU:
				DWGameManager.getInstance().getSendMessage().sendTuijianHaoyou();
				break;
			case TUIJIAN_SHIFU:
				DWGameManager.getInstance().getSendMessage().sendTuijianShifu();
				break;
			case TUIJIAN_TUDI:
				DWGameManager.getInstance().getSendMessage().sendTuijianTudi();
				break;
		}
	}

	public void close(byte index)
	{
		switch (index) {
			case TUIJIAN_HAOYOU:
				DWControlsManager.getInstance().removeControl(m_haoyou_Frame);
				DWControlsManager.getInstance().removeControl(m_haoyou_list);
				break;
			case TUIJIAN_SHIFU:
				DWControlsManager.getInstance().removeControl(m_shifu_Frame);
				DWControlsManager.getInstance().removeControl(m_shifu_list);
				break;
			case TUIJIAN_TUDI:
				DWControlsManager.getInstance().removeControl(m_tudi_Frame);
				DWControlsManager.getInstance().removeControl(m_tudi_list);
				break;
		}
	}

	public void dispose()
	{

	}

	public void logic()
	{

	}

	/**
	 * 接收推荐好友
	 * @param dis
	 * @throws IOException
	 */
	public void readTuijianHaoyou(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_推荐);
		try {
			readDataList(dis);
			tuijian_haoyou();
			list_haoyou();
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 接收推荐徒弟
	 * @param dis
	 * @throws IOException
	 */
	public void readTuijianTudi(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_推荐);
		try {
			readDataList(dis);
			tuijian_tudi();
			list_tudi();
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	/**
	 * 接收推荐师傅
	 * @param dis
	 * @throws IOException
	 */
	public void readTuijianShifu(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_推荐);
		try {
			readDataList(dis);
			tuijain_shifu();
			list_shifu();
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}

	public void readDataList(DataInputStream dis) throws IOException
	{
		try {
			byte size = dis.readByte();
			Tools.debugPrintln("推荐列表长度------>" + size);
			m_data_list.clear();
			SimpleRole role = null;
			for (int i = 0; i < size; i++) {
				role = new SimpleRole();
				role.m_gameID = dis.readLong();
				role.m_name = dis.readUTF();
				role.m_grade = dis.readInt();
				role.m_vocation = dis.readByte();
				role.m_camp = dis.readByte();
				m_data_list.add(role);
				role = null;
			}
		}
		catch (Exception e) {
			Tools.debug(e);
		}
	}
}
